package com.ruoyi.dl.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.dl.domain.DlOrders;
import com.ruoyi.dl.mapper.DlOrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.dl.mapper.DlAbnormalMapper;
import com.ruoyi.dl.domain.DlAbnormal;
import com.ruoyi.dl.service.IDlAbnormalService;
import com.ruoyi.common.core.text.Convert;

/**
 * 异常管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-12-28
 */
@Service
public class DlAbnormalServiceImpl implements IDlAbnormalService 
{
    @Autowired
    private DlAbnormalMapper dlAbnormalMapper;

    @Autowired
    private DlOrdersMapper dlOrdersMapper;

    /**
     * 查询异常管理
     * 
     * @param id 异常管理ID
     * @return 异常管理
     */
    @Override
    public DlAbnormal selectDlAbnormalById(Integer id)
    {
        return dlAbnormalMapper.selectDlAbnormalById(id);
    }

    /**
     * 查询异常管理列表
     * 
     * @param dlAbnormal 异常管理
     * @return 异常管理
     */
    @Override
    public List<DlAbnormal> selectDlAbnormalList(DlAbnormal dlAbnormal)
    {
        return dlAbnormalMapper.selectDlAbnormalList(dlAbnormal);
    }
    //关联
    @Override
    public List<DlAbnormal> newSelectDlAbnormalList(DlAbnormal dlAbnormal)
    {
        return dlAbnormalMapper.newSelectDlAbnormalList(dlAbnormal);
    }
    /**
     * 新增异常管理
     * 
     * @param dlAbnormal 异常管理
     * @return 结果
     */
    @Override
    public int insertDlAbnormal(DlAbnormal dlAbnormal)
    {
        DlOrders dlOrders = new DlOrders();
        dlOrders.setOrdersNumber(dlAbnormal.getOrdersNumber());
        List<DlOrders> orders = dlOrdersMapper.selectDlOrdersList(dlOrders);
        DlOrders order = orders.get(0);
        order.setOrdersType(2);
        dlOrdersMapper.updateDlOrders(order);
        dlAbnormal.setCreateTime(DateUtils.getNowDate());
        return dlAbnormalMapper.insertDlAbnormal(dlAbnormal);
    }

    /**
     * 修改异常管理
     * 
     * @param dlAbnormal 异常管理
     * @return 结果
     */
    @Override
    public int updateDlAbnormal(DlAbnormal dlAbnormal)
    {
        return dlAbnormalMapper.updateDlAbnormal(dlAbnormal);
    }

    /**
     * 删除异常管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteDlAbnormalByIds(String ids)
    {
        return dlAbnormalMapper.deleteDlAbnormalByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除异常管理信息
     * 
     * @param id 异常管理ID
     * @return 结果
     */
    @Override
    public int deleteDlAbnormalById(Integer id)
    {
        return dlAbnormalMapper.deleteDlAbnormalById(id);
    }
}
